<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <script type="text/javascript">
        var id = "${id}";
        var submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {

//                var url=sy.contextPath + '/goods/checkNum';
//                var data = {}
//                $.post(url, data, function(result) {
//                    if (result.code == 0) {
//                        var obj=sy.serializeObject($('form'));
//                        var url=sy.contextPath + '/goodsSuggest/save';
//                        if($("#goodsId").combobox('getValue') != null){
//                            obj.id = $("#goodsId").combobox('getValue');
//                        }
//
//                        //obj.goodsName = $("#goodsId").combobox('getText');
//                        obj.isToday = 1;
//                        $.post(url, obj, function(result) {
//                            if (result.code == 0) {
//
//                                $grid.datagrid('reload');
//                                $dialog.dialog('destroy');
//                            } else {
//                                $pjq.messager.e('保存失败,'+result.msg);
//                            }
//                        }, 'json');
//                    } else {
//                        $pjq.messager.e('保存失败,'+result.msg);
//                    }
//                }, 'json');
                var obj=sy.serializeObject($('form'));
                var url=sy.contextPath + '/goodsSuggest/save';
                if($("#goodsId").combobox('getValue') != null){
                    obj.goodsId = $("#goodsId").combobox('getValue');
                }
                obj.img = $('#img').getFileId();

                //obj.goodsName = $("#goodsId").combobox('getText');
                obj.state = 0;
                obj.info = editor.getHtml();
                $.post(url, obj, function(result) {
                    if (result.code == 0) {

                        $grid.datagrid('reload');
                        $dialog.dialog('destroy');
                    } else {
                        $pjq.messager.e('保存失败,'+result.msg);
                    }
                }, 'json');


            }
        };

        $(function() {
            editor = new HtmlEditor('#info');
            $('#goodsId').combobox({
                url:sy.contextPath+"/goods/goodsList",
                textField:'goodsName',
                valueField:'id',
                editable:false
            })

            if (id != '') {
                parent.$.messager.progress({
                    text : '数据加载中....'
                });
                $.post(sy.contextPath + '/goods/findById', {
                    id : id
                }, function(result) {
                    $('#img').setFileId(result.showImg,false,1,true);
                    if (result) {
                        $('form').form('load', result);
                    }
                    parent.$.messager.progress('close');
                }, 'json');
            }
        });
    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
            <tr>
                <th style="width:100px;">艺术品名称：</th>
                <td colspan="3">
                    <input id="goodsId" name="goodsName" class="easyui-commbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:false" />
                </td>
            </tr>
            <tr>
                <th style="width:100px;">封面：</th>
                <td colspan="3">
                    <div id="img" multi="false" fileCountLimit="1" type="file" showImage="true" bestSize="640*320" fileType="jpg,png"
                         showWidth="40" showHeight="40" fileSize="2MB" buttonText="每日艺术品封面" url="fileUpload"></div>
                </td>
            </tr>
            <tr>
                <th style="width:100px;">宽：(建议尺寸720)</th>
                <td>
                    <input id="width" name="width" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true" />
                </td>
                <th style="width:100px;">高：(建议尺寸340)</th>
                <td>
                    <input id="height" name="height" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true" />
                </td>
            </tr>
            <tr>
                <th style="width:100px;">详情</th>
                <td colspan="3">
                    <textarea id="info" style="width:98%;height: 450px"></textarea>
                </td>
            </tr>
        </table>
    </div>
</form>
</body>
</html>